﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PRO.User;
using PRO.Common;
using PRO.Config;

namespace web.Member
{
    public partial class login : PageBase
    {
        protected string error_msg;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "会员登录-" + BaseConfigs.Title;
            if (UserInfo.ID > 0)
            {
                if (CVGRequest.GetQueryString("url").IsNullOrWhiteSpace())
                    Response.Redirect("/member");
                else
                    Response.Write(CVGRequest.GetQueryString("url"));
            }
            this.txtUserName.Focus();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.txtUserName.Text.IsNullOrWhiteSpace())
            {
                error_msg = "登陆用户名不能为空！";
                return;
            }
            else {
                if (!this.txtUserName.Text.IsEmail())
                {
                    error_msg = "用户名必须是邮箱地址！";
                    return;
                }
            }
            if (this.txtPwd.Text.IsNullOrWhiteSpace())
            {
                error_msg = "登陆密码不能为空！";
                return;
            }

            if (UserLib.Login(txtUserName.Text, Utils.MD5(this.txtPwd.Text), out error_msg))
            {
                if (CVGRequest.GetQueryString("url").IsNullOrWhiteSpace())
                    Response.Redirect("/member");
                else
                    Response.Redirect(CVGRequest.GetQueryString("url"));
            }
            else
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('" + error_msg + "');</script>");     
        }
    }
}